package com.ruoyi.project.outpatient.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hissystem.domain.HisDepartment;
import com.ruoyi.project.outpatient.domain.OutPatient;
import com.ruoyi.project.outpatient.service.OutPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 *门诊挂号
 */
import java.util.List;

@RestController
@RequestMapping("/outpatient/patient")
public class OutPatientController extends BaseController {

    @Autowired
    private OutPatientService outPatientService;

    @PreAuthorize("@ss.hasAnyPermi('outpatient:register:list')")
    @GetMapping("/list")
    public TableDataInfo findPatientInfo(OutPatient outPatient){
        startPage();
        List<OutPatient> list = outPatientService.selectPatientList(outPatient);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('outpatient:register:add')")
    @Log(title = "新增患者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody OutPatient outPatient)
    {
        outPatient.setCreateBy( SecurityUtils.getUsername());
        return toAjax(outPatientService.insertOutpatientInfo(outPatient));
    }

    @GetMapping("/list4")
    public AjaxResult findRegisterType()
    {
        List<HisDepartment> sysDepts = outPatientService.selectDeptList();
        return AjaxResult.success(sysDepts);
    }

    /**
     * 获取患者选择框列表
     */
    @GetMapping("/list5")
    public AjaxResult selectRegisterInfo2()
    {
        List<OutPatient> registers = outPatientService.selectRegisterInfo2();
        System.out.println(registers);
        return AjaxResult.success(registers);
    }
}
